package cn.wyz.org.service.impl;

import cn.wyz.basic.query.BaseQuery;
import cn.wyz.basic.service.impl.BaseServiceImpl;
import cn.wyz.basic.util.PlusQueryList;
import cn.wyz.org.domain.DictionaryDetail;
import cn.wyz.org.mapper.DictionaryDetailMapper;
import cn.wyz.org.query.DictionaryDetailQuery;
import cn.wyz.org.service.IDictionaryDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DictionaryDetailServiceImpl extends BaseServiceImpl<DictionaryDetail> implements IDictionaryDetailService {

    @Autowired
    private DictionaryDetailMapper mapper;

    @Override
    public void update(DictionaryDetail detail) {
        if(detail.getTypes_id()!=null){
            detail.setTypes_id(detail.getType().getId());
        }
        mapper.update(detail);
    }

    @Override
    public PlusQueryList<DictionaryDetail> queryDetails(DictionaryDetailQuery query) {
           Long total = mapper.queryCount(query);
           List<DictionaryDetail> details = mapper.queryDetails(query.getTypes_id());
           return new PlusQueryList<DictionaryDetail>(total,details);
    }

}
